package logic

import (
	"context"
	"fmt"
	"person/model"

	"person/personrpc/internal/svc"
	"person/personrpc/personrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserShowLogic {
	return &UserShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserShowLogic) UserShow(in *personrpc.UserShowRequest) (*personrpc.UserShowResponse, error) {
	// todo: add your logic here and delete this line
	var user model.User
	model.DB.Where("id", in.UserId).Find(&user)
	if user.ID == 0 {
		return nil, fmt.Errorf("用户未注册请去注册")
	}
	return &personrpc.UserShowResponse{
		Account:  user.Account,
		Password: user.Password,
	}, nil
}
